/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class StaticDDI {
    /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://example.org/ddi2/";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>The group of persons or other elements that are the object of research and to which any analytic results refer.</p> */
    public static final Property universe = m_model.createProperty( "http://example.org/ddi2/universe" );
    
    /** <p>The time method or time dimension of the data collection.</p> */
    public static final Property timeMethod = m_model.createProperty( "http://example.org/ddi2/timeMethod" );
    
    /** <p>The entity (individual, agency, or institution) responsible for administering the questionnaire or interview or compiling the data. This refers to the entity collecting the data, not to the entity producing the documentation.</p> */
    public static final Property dataCollector = m_model.createProperty( "http://example.org/ddi2/dataCollector" );
    
    /** <p>The type of sample and sample design used to select the survey respondents to represent the population.</p> */
    public static final Property samplingProcedure = m_model.createProperty( "http://example.org/qudex/samplingProcedure" );
    
    /** <p>The method used to collect the data; instrumentation characteristics.</p> */
    public static final Property collectionMode = m_model.createProperty( "http://example.org/ddi2/collectionMode" );
     
    public static Model getModel() {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("ddi2.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}              
    }
    
    public static boolean containsProperty(String localName) {
    	if (StaticDDI.universe.getLocalName().equals(localName) ||
    		StaticDDI.collectionMode.getLocalName().equals(localName) ||
    		StaticDDI.dataCollector.getLocalName().equals(localName) ||
    		StaticDDI.samplingProcedure.getLocalName().equals(localName) ||
    		StaticDDI.timeMethod.getLocalName().equals(localName))
    	    return true;
    	else return false;
    }
}
